package com.example.demo.utils;

import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import org.springframework.http.HttpStatus;

import java.util.HashMap;
import java.util.Map;

@Setter
@Getter
@AllArgsConstructor
@NoArgsConstructor
public class ApiResponse {

    private Map<String, Object> data;

    // 重写 toString 方法，方便调试
    @Override
    public String toString() {
        return "ApiResponse{" +
                "data=" + data +
                '}';
    }

    // 构建普通的响应式信息
    public static Map<String, Object> messageResult(String message, HttpStatus status) {
        Map<String, Object> data = new HashMap<>();
        data.put("message", message);
        data.put("status", status.value());
        return data;
    }

    public static Map<String, Object> messageResult(String message, HttpStatus status, String token) {
        Map<String, Object> data = messageResult(message, status);
        data.put("token", token);
        return data;
    }

    public static <T> Map<String, Object> messageResultWithData(String message, HttpStatus status, T data) {
        Map<String, Object> resultData = messageResult(message, status);
        resultData.put("data", data);
        return resultData;
    }

}